<?php
/**
 * 酒类附加属性的操作
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/12/012
 * Time: 下午 2:22
 */

namespace app\service;
use think\Db;

class WineAddtionAttrService
{
    /**
     * 白酒类，附加属性的
     * @param $common_id
     * @param array $data
     * @return mixed
     */
    public function updateWineAddtionalAttr($common_id,$data = [])
    {
        //有数据记录，更新。无：就新增
        $raw = Db::name('goods_wine_attr')->where(['goods_common_id'=>$common_id])->column('wa_id');

        if(empty($raw)) return  Db::name('goods_wine_attr')->insert($data);

        return  Db::name('goods_wine_attr')->where(['goods_common_id'=>$common_id])->update($data);
    }
    /**
     * 红酒类，附加属性的
     * @param $common_id    商品公共ID编号
     * @param array $data   红酒相关附加属性
     * @return mixed
     */
    public function updateRedWineAddtionalAttr($common_id,$data = [])
    {
        //多选的字段，处理一下
        $data['drinking_scenario'] = implode(',',$data['drinking_scenario']);   #饮酒场合（多选）
        $data['grapes_kinds'] = implode(',',$data['grapes_kinds']); #葡萄品种（多选）
        $data['fragrance'] = implode(',',$data['fragrance']);   #香味（多选）
        //有数据记录，更新。无：就新增
        $raw = Db::name('goods_redwine_attr')->where(['goods_common_id'=>$common_id])->column('gr_id');

        if(empty($raw)) return  Db::name('goods_redwine_attr')->insert($data);

        return  Db::name('goods_redwine_attr')->where(['goods_common_id'=>$common_id])->update($data);
    }
}